layui.config({
	base : "js/"
}).use(['form','layer','jquery','laypage'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		$ = layui.jquery;

	$.ajax({
		url : 'admincompany_auditList',
		type : "get",
		dataType : "json",
		beforeSend:function(){
			querylistalert = layer.msg('查询中，请稍候',{icon: 16,time:false,shade:0.8});
		},
		success : function(data){
			layer.close(querylistalert);
			linksData = data;
			//执行加载数据的方法
			linksList();
		},
	});

	//查询
	$(".search_btn").click(function(){
		var newArray = [];
		if($(".search_input").val() != ''){
			var index = layer.msg('查询中，请稍候',{icon: 16,time:false,shade:0.8});
            	$.ajax({
					url :'admincompany_findByKey?key=comp_name&value='+$(".search_input").val(),
					type : "get",
					dataType : "json",
					success : function(data){
						linksData = data;
						linksList();
					}
				})
                layer.close(index);
		}else{
			layer.msg("请输入需要查询的内容");
		}
	})

	//添加友情链接

	//批量删除

	//全选

	//查看详情跳转操作
	$("body").on("click",".company_detail",function(){  //编辑
		var index = layui.layer.open({
			title : "详细信息",
			type : 2,
			content : 'listDetail.html?id='+$(this).attr('data-id'),
			success : function(layero, index){
				setTimeout(function(){
					layui.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
						tips: 3
					});
				},1000)
			}
		})
		//改变窗口大小时，重置弹窗的高度，防止超出可视区域（如F12调出debug的操作）
		$(window).resize(function(){
			layui.layer.full(index);
		})
		layui.layer.full(index);
	
	})


	function linksList(that){
		//渲染数据
		function renderDate(data,curr){
			var dataHtml = '';
			if(!that){
				currData = linksData.concat().splice(curr*nums-nums, nums);
			}else{
				currData = that.concat().splice(curr*nums-nums, nums);
			}
			if(currData.length != 0){
				for(var i=0;i<currData.length;i++){
					dataHtml += '<tr>'
			    	+'<td><input type="checkbox" name="checked" lay-skin="primary" lay-filter="choose"></td>'
			    	+'<td align="center">'+(i+1)+'</td>'
			    	+'<td>'+currData[i].comp_name+'</a></td>'
			    	+'<td>'+currData[i].comp_code+'</td>'
			    	+'<td>'+currData[i].profile.pro_phone+'</td>'
			    	+'<td>'+currData[i].profile.pro_email+'</td>'
			    	+'<td>'+currData[i].profile.pro_address+'</td>'
			    	+'<td>'+currData[i].profile.pro_intro+'</td>'
			    	+'<td>'
					+  '<a class="layui-btn layui-btn-mini company_detail" data-id="'+currData[i].comp_id+'"><i class="layui-icon">&#xe60a;</i>查看详细</a>'
			        +'</td>'
			    	+'</tr>';
				}
			}else{
				dataHtml = '<tr><td colspan="9">暂无数据</td></tr>';
			}
		    return dataHtml;
		}

		//分页
		var nums = 8; //每页出现的数据量
		if(that){
			linksData = that;
		}
		laypage({
			cont : "page",
			pages : Math.ceil(linksData.length/nums),
			jump : function(obj){
				$(".links_content").html(renderDate(linksData,obj.curr));
				$('.links_list thead input[type="checkbox"]').prop("checked",false);
		    	form.render();
			}
		})
	}
})
